package com.push.notnoop.biyao.com;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;

public class IOSPushRunnable implements Runnable{
	private static String keystore = IOSPushRunnable.class.getClassLoader().getResource("").getPath()+"biyaoPush.p12";
//	private static String keystore = "F:/circle_workfile/biyaoPush.p12";
	private static String password = "biyaoPush";
	private static Queue<String> cqueue = new ConcurrentLinkedQueue<String>();
	private String payload;
	private Queue<String> queue;
	
	public IOSPushRunnable(String payload,Queue<String> queue){
		this.payload = payload;
		this.queue = queue;
	}
	
	public static void toPush(String payload,Queue<String> queue){
//		String payload = APNS.newPayload().badge(10).alertBody(message).build();
		cqueue = queue;
        while (cqueue.peek() != null) {   
    		getApnsService().push(cqueue.poll(), payload);
        } 
	}
	
	public static ApnsService getApnsService(){
		
		ApnsService service = APNS.newService().withCert(keystore, password).withProductionDestination().build();
		return service;
	}

	public void run() {
		// TODO Auto-generated method stub
		IOSPushRunnable.toPush(payload, queue);
	}
}
